//公共方法和按钮
import 'package:flutter/material.dart';
import 'color.dart';
import 'rpx.dart';

///突出 确定 按钮
Widget outSubmitButton({
  String title = '确定',
  required Function()? confirmFun,
  Color bgColor = SzColor.primary,
  Color titleColor = Colors.white,
  double borderRadius = 10,
  double width = 120,
  double height = 60,
}) {
  return InkWell(
    onTap: confirmFun,
    child: Container(
      alignment: Alignment.center,
      decoration: BoxDecoration(
          color: bgColor,
          borderRadius: BorderRadius.circular(
            rpx(borderRadius),
          )),
      width: rpx(width),
      height: rpx(height),
      child: Text(
        title,
        style: TextStyle(color: titleColor, fontSize: setSp(28)),
      ),
    ),
  );
}

///突出 取消 按钮
Widget outCancelButton(
  BuildContext context, {
  String title = '取消',
  Color bgColor = const Color.fromARGB(255, 204, 201, 197),
  double borderRadius = 10,
  double width = 140,
  double height = 60,
}) {
  return InkWell(
    onTap: () {
      Navigator.of(context).pop();
    },
    child: Container(
      alignment: Alignment.center,
      decoration: BoxDecoration(
          color: bgColor,
          borderRadius: BorderRadius.circular(
            rpx(borderRadius),
          )),
      width: rpx(width),
      height: rpx(height),
      child: Text(
        title,
        style: TextStyle(fontSize: setSp(28)),
      ),
    ),
  );
}

///确定按钮 文字
///title文字confirmFun方法color文字颜色
Widget confirmTextButtn({
  String title = '确定',
  required Function()? confirmFun,
  Color color = SzColor.primary,
  double width = 300,
  double height = 90,
  double borderRadius = 0,
  double fontSize = 30,
}) {
  return TextButton(
    onPressed: confirmFun,
    style: ButtonStyle(
      fixedSize: MaterialStateProperty.all(
        //大小
        Size(rpx(width), rpx(height)),
      ),
      shape: MaterialStateProperty.all(
        //圆角
        RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(
            rpx(borderRadius),
          ),
        ),
      ),
    ),
    child: Text(
      title,
      style: TextStyle(
        fontSize: setSp(fontSize),
        color: color,
      ),
    ),
  );
}

///取消按钮
///title文字color文字颜色
Widget cancelTextButtn(
  BuildContext context, {
  String title = '取消',
  Function? cancelFun,
  Color color = Colors.black54,
  double width = 300,
  double height = 90,
  double borderRadius = 0,
  double fontSize = 30,
}) {
  return TextButton(
    onPressed: () {
      Navigator.of(context).pop();
      cancelFun!();
    },
    style: ButtonStyle(
      fixedSize: MaterialStateProperty.all(
        //大小
        Size(rpx(width), rpx(height)),
      ),
      shape: MaterialStateProperty.all(
        //圆角
        RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(
            rpx(borderRadius),
          ),
        ),
      ),
    ),
    child: Text(
      title,
      style: TextStyle(
        fontSize: setSp(fontSize),
        color: color,
      ),
    ),
  );
}

///键盘回收
keyboardRecycling(BuildContext context) {
  FocusScopeNode currentFocus = FocusScope.of(context);
  if (!currentFocus.hasPrimaryFocus && currentFocus.focusedChild != null) {
    FocusManager.instance.primaryFocus!.unfocus();
  }
}
